package com.atguigu.wulaoshi

object MyWhile2 {
  def main(args: Array[String]): Unit = {
    var n = 10
    while (n >= 1) {
      print(n)
      n -= 1
    }
    println("----------------------")

    //用闭包实现一个函数,将代码块作为参数传入
    def myWhile(condition: => Boolean): (=> Unit) => Unit = {
      def doLoop(op: => Unit): Unit = {
        if (condition) {
          op
          myWhile(condition)(op)
        }
      }
        doLoop
    }
    def myWhile2(condition: => Boolean): (=> Unit) => Unit = {
op=> {
        if (condition) {
          op
          myWhile2(condition)(op)
        }
      }
    }
    def myWhile3(condition: =>Boolean)(op: =>Unit):Unit={
      if(condition){
        op
        myWhile3(condition)(op)
      }
    }
  }
  }
